package com.taptech.doufu.ui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

/**
 */
@SuppressLint({ "Recycle", "NewApi" })
public class PersonalPointListView extends ListView {


	private int headContentHeight;
	public PersonalPointListView(Context context) {
		super(context);
	}

	public PersonalPointListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public PersonalPointListView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}



	public boolean onTouchEvent(MotionEvent event) {
		return super.onTouchEvent(event);
	}

	// 计算headView的width及height值
	private void measureView(View child) {
		ViewGroup.LayoutParams p = child.getLayoutParams();
		if (p == null) {
			p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
		}
		int lpHeight = p.height;
		int childHeightSpec;
		if (lpHeight > 0) {
			childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight,
					MeasureSpec.EXACTLY);
		} else {
			childHeightSpec = MeasureSpec.makeMeasureSpec(0,
					MeasureSpec.UNSPECIFIED);
		}
//		child.measure(childWidthSpec, childHeightSpec);
	}



	@Override
	public void addHeaderView(View v) {
//		this.headView = (LinearLayout) v;
		measureView(v);
		headContentHeight = v.getMeasuredHeight();
		v.invalidate();
		v.setPadding(v.getPaddingLeft(), 1 * headContentHeight,
				v.getPaddingRight(), v.getPaddingBottom());
		
		super.addHeaderView(v);
	}
}
